Verify cluster in API server before deleting namespace#4736
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the cleanup controller’s decision to delete fleet-managed cluster namespaces by confirming cache “not found” results against the live API server, preventing erroneous namespace deletion during cache warm-up or under load (ref #3830).
Changes:
- Pass a
ClusterClientinto the cleanup controller so it can query the live API when the cache reports a missing Cluster. - Update
cleanupNamespaceto only delete the namespace after both cache and live API calls return NotFound for the Cluster. - Add a focused unit test suite covering cache-hit, cache-miss/API-hit, and true-not-found scenarios.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/cmd/controller/cleanup/controllers/controllers.go | Wires the Cluster controller into cleanup registration so a live Cluster GET can be performed. |
| internal/cmd/controller/cleanup/controllers/cleanup/controller.go | Implements the cache-first, API-confirmed Cluster existence check before namespace deletion. |
| internal/cmd/controller/cleanup/controllers/cleanup/controller_test.go | Adds tests validating the new cache-miss verification behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The cleanup controller used only the informer cache to decide whether a fleet-managed namespace should be removed. During startup or under load, the cache may not yet contain a newly created Cluster, causing the namespace to be wrongly deleted and breaking bundle deployment. Confirm a cache not-found result with a live API call before deleting the namespace.
p-se
approved these changes
Mar 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The cleanup controller used only the informer cache to decide whether a fleet-managed namespace should be removed. During startup or under load, the cache may not yet contain a newly created Cluster, causing the namespace to be wrongly deleted and breaking bundle deployment.
Confirm a cache not-found result with a live API call before deleting the namespace.
Refers to #3830